package base;

import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.constraintlayout.widget.ConstraintLayout;

import com.aimer.common.R;
import com.aimer.common.databinding.BaseLoadingDialogBinding;
import com.alibaba.android.arouter.utils.TextUtils;
import com.wang.avi.AVLoadingIndicatorView;

public class QLoading extends QDialogFragment<BaseLoadingDialogBinding> {
    private String title;

    public QLoading(String title) {
        this.title = title;
    }

    public QLoading() {
        title = null;
    }

//    public static void showDialogForLoading(Context context, String msg) {
//        View view = LayoutInflater.from(context).inflate(R.layout.layout_loading_dialog, null);
////        TextView loadingText = (TextView) view.findViewById(R.id.id_tv_loading_dialog_text);
////        AVLoadingIndicatorView avLoadingIndicatorView = (AVLoadingIndicatorView) view.findViewById(R.id.AVLoadingIndicatorView);
////        loadingText.setText(msg);
////
////            mLoadingDialog = new Dialog(context, R.style.loading_dialog_style);
////            mLoadingDialog.setCancelable(false);
////            mLoadingDialog.setContentView(view, new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
////                    LinearLayout.LayoutParams.MATCH_PARENT));
////
////            mLoadingDialog.show();
////            avLoadingIndicatorView.smoothToShow();
////            mLoadingDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
////                @Override
////                public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
////                    if (keyCode == KeyEvent.KEYCODE_BACK) {
////                        mLoadingDialog.hide();
////                        return true;
////                    }
////                    return false;
////                }
////            });
//
//
//    }


    @Override
    public int getLayoutRes() {
        return R.layout.base_loading_dialog;
    }

    @Override
    public void initView() {

//        AVLoadingIndicatorView avLoadingIndicatorView = (AVLoadingIndicatorView) view.findViewById(R.id.AVLoadingIndicatorView);
        if (TextUtils.isEmpty(title)) {
            binding.idTvLoadingDialogText.setText("别急，正在加载中");
        }else {
            binding.idTvLoadingDialogText.setText(title);
        }


//        Dialog mLoadingDialog = new Dialog(getContext(), R.style.loading_dialog_style);
//        mLoadingDialog.setCancelable(false);
//        mLoadingDialog.setContentView(binding.getRoot().getRootView(), new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
//                LinearLayout.LayoutParams.MATCH_PARENT));
//
//        mLoadingDialog.show();
        binding.AVLoadingIndicatorView.smoothToShow();
//        mLoadingDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
//            @Override
//            public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
//                if (keyCode == KeyEvent.KEYCODE_BACK) {
//                    mLoadingDialog.hide();
//                    return true;
//                }
//                return false;
//            }
//        });
    }

    @Override
    public void initData() {

    }

    @Override
    public void initListener() {

    }

    @Override
    public void networkMessage() {

    }
}
